package com.hsteach.enums;

import com.hsteach.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Calendar;

@Getter
@AllArgsConstructor
public enum TimeEnum {
    ALL(0, "all", 0, Calendar.ALL_STYLES),
    DAY(1, "day", 1, Calendar.DATE),
    WEEK(2, "week", 7, Calendar.DATE),
    TWO_WEEK(3, "two_week", 14, Calendar.DATE),
    MONTH(4, "month", 1, Calendar.MONTH)
    ;

    private Integer code;
    private String strCode;
    private Integer offset;
    private int calendarType;

    public static TimeEnum getByCode(Integer code) {
        TimeEnum timeEnum = Arrays.stream(TimeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        if (timeEnum == null) {
            throw new ServiceException("不存在的查询时段类型");
        }
        return timeEnum;
    }
}
